home *** CD-ROM | disk | FTP | other *** search
- /*
- * CBLibrary - NoBudge
- * Copyright (C) 2003 Chris Bazley
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
- /* Keeps track of multiple operations that require flex budge disabled */
-
- /* ANSI library files */
- #include <assert.h>
- #include <stdlib.h>
-
- /* RISC OS library files */
- #include "kernel.h"
- #include "flex.h"
-
- /* My library files */
- #include "NoBudge.h"
-
- extern _kernel_oserror shared_err_block;
- static int default_state, num_no_budge = 0;
-
- /* ----------------------------------------------------------------------- */
- /* Public functions */
-
- void nobudge_register(size_t heap_ensure)
- {
- free(malloc(heap_ensure));
-
- if(num_no_budge == 0) {
- /* We have first client - disable flex budging */
- #ifndef NDEBUG
- _kernel_oscli("report NoBudge has first client - disabling flex budging");
- #endif
- default_state = flex_set_budge(0);
- }
- #ifndef NDEBUG
- _kernel_oscli("report Incrementing NoBudge count");
- #endif
- num_no_budge++;
- }
-
- /* ----------------------------------------------------------------------- */
-
- void nobudge_deregister(void)
- {
- /* Can't deregister if there are no clients! */
- assert(num_no_budge >= 1);
- if(num_no_budge < 1)
- return; /* bad deregistration */
-
- if(num_no_budge == 1) {
- /* We have run out of clients - enable flex budging */
- #ifndef NDEBUG
- _kernel_oscli("report Last NoBudge client has deregistered - restoring flex budge state");
- #endif
- flex_set_budge(default_state);
- }
-
- #ifndef NDEBUG
- _kernel_oscli("report Decrementing NoBudge count");
- #endif
- num_no_budge--;
- }
-